package com.spic.business.mountguard.service.impl;

import com.spic.business.mountguard.domain.MountSign;
import com.spic.business.mountguard.mapper.MountSignMapper;
import com.spic.business.mountguard.service.IMountSignService;
import com.spic.business.qrcode.domain.QRCodeResult;
import com.spic.business.qrcode.service.QrService;
import com.spic.common.core.utils.DateUtils;
import com.spic.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 上岗签到表Service业务层处理
 *
 * @author spic
 * @date 2021-12-05
 */
@Service
public class MountSignServiceImpl implements IMountSignService
{
    @Autowired
    private MountSignMapper mountSignMapper;

    @Autowired
    private QrService qrService;

    /**
     * 查询上岗签到表
     *
     * @param id 上岗签到表主键
     * @return 上岗签到表
     */
    @Override
    public MountSign selectMountSignById(String id)
    {
        return mountSignMapper.selectMountSignById(id);
    }

    /**
     * 查询上岗签到表列表
     *
     * @param mountSign 上岗签到表
     * @return 上岗签到表
     */
    @Override
    public List<MountSign> selectMountSignList(MountSign mountSign)
    {
        return mountSignMapper.selectMountSignList(mountSign);
    }

    /**
     * 新增上岗签到表
     *
     * @param mountSign 上岗签到表
     * @return 结果
     */
    @Override
    public int insertMountSign(MountSign mountSign)
    {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        mountSign.setId(uuid);
        mountSign.setCreatBy(SecurityUtils.getUsername());
        mountSign.setCreatTime(DateUtils.getNowDate());
        QRCodeResult qrCodeResult = new QRCodeResult();
        qrCodeResult.setId(uuid);
        qrCodeResult.setType("0");
        String qrCode =  qrService.createAPPLink(qrCodeResult).getCode();
        mountSign.setQrCode(qrCode);
        return mountSignMapper.insertMountSign(mountSign);
    }

    /**
     * 修改上岗签到表
     *
     * @param mountSign 上岗签到表
     * @return 结果
     */
    @Override
    public int updateMountSign(MountSign mountSign)
    {
        return mountSignMapper.updateMountSign(mountSign);
    }

    /**
     * 批量删除上岗签到表
     *
     * @param ids 需要删除的上岗签到表主键
     * @return 结果
     */
    @Override
    public int deleteMountSignByIds(String[] ids)
    {
        return mountSignMapper.deleteMountSignByIds(ids);
    }

    /**
     * 删除上岗签到表信息
     *
     * @param id 上岗签到表主键
     * @return 结果
     */
    @Override
    public int deleteMountSignById(String id)
    {
        return mountSignMapper.deleteMountSignById(id);
    }
}
